//
//  IMessageImageNode.m
//  imessagesender
//
//  Created by Pang lei on 13-7-25.
//  Copyright (c) 2013年 Pang lei. All rights reserved.
//

#import "IMessageImageNode.h"
#import "IMessageTaskContext.h"

@implementation IMessageImageNode

@synthesize uri=_uri;

- (id) initWithUri:(NSString *)uri
{
    if(self = [super init]) {
        self.uri = uri;
    }
    return self;
}

- (NSString *) getVarname
{
    NSTimeInterval timeStampInterval = [[NSDate date] timeIntervalSince1970];
    NSInteger timestamp = timeStampInterval;
    NSString *varname = [NSString stringWithFormat:@"att_%ld", timestamp];
    return varname;
}

- (NSString *)toScript
{
    NSString *varname = [self getVarname];
    IMessageTaskContext *context = [IMessageTaskContext shareIMessageTaskContext];
    NSString *imagePath = [NSString stringWithFormat:@"%@/%@",  context.tmpDir, self.uri];
    NSString *script1 = [NSString stringWithFormat:@"set %@ to POSIX file \"%@\"\n", varname, imagePath];
    NSString *script2 = [NSString stringWithFormat:@"send %@ to buddy \"%@\" of service \"E:%@\"\n\n", varname, context.recipient, context.sender];
    
    return [NSString stringWithFormat:@"%@\n%@", script1, script2];
}

@end
